#include "parafluidmainwindow.h"
#include "parafluidsimulation.h"

#include <QApplication>
#include <QDockWidget>
#include <QStatusBar>
#include <QThread>

using namespace ParaFluid;

MainWindow::~MainWindow()
{
	/* does nothing */
}

MainWindow::MainWindow()
	: QMainWindow()
	, _widgetSimulation(new SimulationWidget(this))
	, _widgetSimulationSettings(new SimulationSettingsWidget(this))
{
	setupUi(this);
	
	QDockWidget * dockWidgetSimulationSettings = new QDockWidget(_widgetSimulationSettings->windowTitle(), this);
	dockWidgetSimulationSettings->setWidget(_widgetSimulationSettings);
	addDockWidget(Qt::RightDockWidgetArea, dockWidgetSimulationSettings);
	menuView->addAction(dockWidgetSimulationSettings->toggleViewAction());
	
	setCentralWidget(_widgetSimulation);
	
	setWindowTitle(QString("ParaFluid (using %1 threads)").arg(QThread::idealThreadCount()));
	
	statusBar()->setVisible(false);
	
	connect(actionQuit, SIGNAL(triggered()), this, SLOT(quit()));
	connect(actionPause, SIGNAL(triggered()), this, SLOT(pause()));
	connect(actionReset, SIGNAL(triggered()), this, SLOT(reset()));
}

void MainWindow::quit()
{
	QApplication::closeAllWindows();
}

void MainWindow::pause()
{
	Simulation::instance().pause();
}

void MainWindow::reset()
{
	Simulation::instance().resetSPH(
		_widgetSimulationSettings->buckets(),
		_widgetSimulationSettings->atoms(),
		_widgetSimulationSettings->substance(),
		2,
		Vector(1.0, 1.0, 1.0)
	);
}
